function isChangeJson(data) {
  let urlsJson = [
    'https://www.etax-gd.gov.cn/',
    "https://etax.guangdong.chinatax.gov.cn/",
    "https://etax.beijing.chinatax.gov.cn/",

  ];
  const href = window.location.href;
  if (urlsJson.find(item => href.includes(item))) {
    return JSON.stringify(data)
  }
  return data;
}
/**
 * {object} info 对象{success: 是否填报成功, tax: 税种, info: 文案}
 *
 * * */
function fillInputDone(info) {
  setTimeout(() => {
    window.postMessage(
      isChangeJson({
        event: 'fillInputDone',
        data: {
          message: info.message
        }
      }),
      '*'
    );
  }, 3000);
}

/** *
 * {string} message 提示信息 必传
 * {object} option  操作 不必传，暂时没用
 *
 */
async function notifications(message, option = {}) {
  return new Promise((resolve) => {
    setTimeout(() => {
      window.postMessage(
        isChangeJson({
          event: 'notifications',
          data: {
            message: message,
            option
          }
        }),
        '*'
      );
      resolve();
    }, 500);
  });
}

function getBaseInfo() {
  window.postMessage(
    isChangeJson({
      event: 'getBaseInfo'
    }),
    '*'
  );
}
function backNationData(data) {
  window.postMessage(
    isChangeJson({
      event: 'backNationData',
      data: data
    }),
    '*'
  );
}

function setPeriodAndType(data) {
  window.postMessage(
    isChangeJson({
      event: 'setPeriodAndType',
      data: data
    }),
    '*'
  );
}



export {
  fillInputDone,
  notifications,
  getBaseInfo,
  backNationData,
  setPeriodAndType
};
